<?php
/**
 * @version     1.0.1
 * @package     com_ganeshavereadores
 * @copyright  	
 * @license     
 * @author      Jorge Eduardo
 */
 

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

/**
 * homenageados View
 */
class ganeshavereadoresViewhomenageados extends JViewLegacy
{
	protected $items;

	protected $pagination;

	protected $state;
	/**
	 * display method of homenageados view
	 * @return void
	 */
	public function display($tpl = null)
	{
		$this->state		= $this->get('State');
		$this->items		= $this->get('Items');
		$this->pagination	= $this->get('Pagination');
	
		// Check for errors.
		if (count($errors = $this->get('Errors'))){
			JError::raiseError(500, implode('<br />', $errors));
			return false;
		};

		// Set the toolbar
		$this->addToolBar();
		$input = JFactory::getApplication()->input;
		$view = $input->getCmd('view', '');
		ganeshavereadoresHelper::addSubmenu($view);
		$this->sidebar = JHtmlSidebar::render();
		// Display the template
		parent::display($tpl);

	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @since	1.6
	 */
	protected function addToolbar()
	{
		require_once JPATH_COMPONENT.'/helpers/ganeshavereadores.php';

		$state	= $this->get('State');
		$canDo	= ganeshavereadoresHelper::getActions($state->get('filter.category_id'));

		JToolBarHelper::title(JText::_('COM_GANESHAVEREADORES_HOMENAGEADOS_TITLE'), '');

        //Check if the form exists before showing the add/edit buttons
        $formPath = JPATH_COMPONENT_ADMINISTRATOR.'/views/homenageado';
        if (file_exists($formPath)) {

            if ($canDo->get('core.create')) {
			    JToolBarHelper::addNew('homenageado.add','JTOOLBAR_NEW');
		    }

		    if ($canDo->get('core.edit') && isset($this->items[0])) {
			    JToolBarHelper::editList('homenageado.edit','JTOOLBAR_EDIT');
		    }

        }

		if ($canDo->get('core.edit.state')) {

            if (isset($this->items[0]->state)) {
			    JToolBarHelper::divider();
			    JToolBarHelper::custom('homenageados.publish', 'publish.png', 'publish_f2.png','JTOOLBAR_PUBLISH', true);
			    JToolBarHelper::custom('homenageados.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
            } else if (isset($this->items[0])) {
                //If this component does not use state then show a direct delete button as we can not trash
                JToolBarHelper::deleteList('', 'homenageados.delete','JTOOLBAR_DELETE');
            }

            if (isset($this->items[0]->state)) {
			    JToolBarHelper::divider();
			    JToolBarHelper::archiveList('homenageados.archive','JTOOLBAR_ARCHIVE');
            }
            if (isset($this->items[0]->checked_out)) {
            	JToolBarHelper::custom('homenageados.checkin', 'checkin.png', 'checkin_f2.png', 'JTOOLBAR_CHECKIN', true);
            }
		}
        
        //Show trash and delete for components that uses the state field
        if (isset($this->items[0]->state)) {
		    if ($state->get('filter.state') == -2 && $canDo->get('core.delete')) {
			    JToolBarHelper::deleteList('', 'homenageados.delete','JTOOLBAR_EMPTY_TRASH');
			    JToolBarHelper::divider();
		    } else if ($canDo->get('core.edit.state')) {
			    JToolBarHelper::trash('homenageados.trash','JTOOLBAR_TRASH');
			    JToolBarHelper::divider();
		    }
        }

		if ($canDo->get('core.admin')) {
			JToolBarHelper::preferences('com_ganeshavereadores');
		}

		JHtmlSidebar::setAction('index.php?option=com_ganeshavereadores&view=homenageados');

	}
	
	/**
	 * Returns an array of fields the table can be sorted by
	 *
	 * @return  array  Array containing the field name to sort by as the key and display text as value
	 *
	 * @since   3.0
	 */
	protected function getSortFields()
	{
		return array(
			'a.ordering' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_ORDERING'),
			'a.nome' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_NOME'),
			'a.data' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_DATA'),
			'a.hora' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_HORA'),
			'a.conteudo' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_CONTEUDO'),
			'vereador_nome' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_VEREADOR'),
			'a.state' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_STATE'),
			'a.checked_out' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_CHECKED_OUT'),
			'a.checked_out_time' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_CHECKED_OUT_TIME'),
			'a.created' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_CREATED'),
			'a.created_by' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_CREATED_BY'),
			'a.create_by_alias' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_CREATE_BY_ALIAS'),
			'a.modified' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_MODIFIED'),
			'a.modified_by' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_MODIFIED_BY'),
			'a.id' => JText::_('COM_GANESHAVEREADORES_LIST_HOMENAGEADOS_ID'),

			);
	}
}
?>